package com.gitee.feizns.explore.data_structure.tree.cus;

import com.gitee.feizns.explore.data_structure.tree.cus.avl.AvlImpl2;

import java.util.Random;
import java.util.function.Consumer;

/**
 * @author feizns
 * @since 2019/11/25
 */
public class Main {

    private static Random random = new Random();

//    public static AvlImpl<Integer, String> ret = new AvlImpl<>();

    public static void main(String[] args) {
        AvlImpl2<Integer, String> ret = new AvlImpl2<>();

        ret.put(1, "1");
        ret.put(2, "1");
        ret.put(3, "1");
        ret.put(4, "1");
        ret.put(5, "1");
        ret.put(6, "1");
        ret.put(7, "1");

        ret.afterEach((k, v) -> System.out.println(k));

//        long time = getTime(i -> ret.put(i, "2"));
//
//        System.out.println(time);
////
//        ret.put(2, "2");
//        System.out.println(time);
//        System.out.println("IS_BALANCED: " + TreeUtils.isBalanced(ret.root()));
//        System.out.println("IS_BST: " + TreeUtils.isBst(ret.root()));
//
//        long time3 = getTime(i -> ret.get(i));
////
//        long time4 = getTime(i -> ret.remove(i));
//        System.out.println(time4);
////
//        System.out.println("===================");
//
//        BstImpl<Integer, String> ret2 = new BstImpl<>();
//        long time2 = getTime(i -> ret2.put(i, "1"));
//        System.out.println(time2);
//        System.out.println("IS_BALANCED: " + TreeUtils.isBalanced(ret2.root()));
//        System.out.println("IS_BST: " + TreeUtils.isBst(ret2.root()));
//
//        long time5 = getTime(i -> ret2.get(i));
//        System.out.println(time5);
//
//        long time6 = getTime(i -> ret2.remove(i));
//        System.out.println(time6);
    }

    private static long getTime(Consumer<Integer> consumer) {
        long start = System.currentTimeMillis();
        for (int i = 0; i < 1000000; i++)
            consumer.accept(random.nextInt(100000));
//            consumer.accept(i);
        long end = System.currentTimeMillis();
        return end - start;
    }

}
